﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using quanlynhasach.Linksql;

namespace quanlynhasach
{
    public partial class frmTimhanghoa : Form
    {
        Connection db = new Connection();
        public frmTimhanghoa()
        {
            InitializeComponent();
        }

        private void frmTimhanghoa_Load(object sender, EventArgs e)
        {
            this.Dock = DockStyle.Fill;
            dataGridView1.DefaultCellStyle.ForeColor = Color.Blue;
            dataGridView1.DataSource = db.getDS("Select * from Sach where MaSach <> 'N/A'");
            rb1.Checked = true;
            dataGridView1.AllowUserToAddRows = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            DataTable HH = new DataTable();
            if (rb2.Checked)
                HH = db.getDS("Select * from Sach Where MaSach LIKE '%" + textBox1.Text + "%' and MaSach <> 'N/A'");
            if (rb3.Checked)
                HH = db.getDS("Select * from Sach Where TenSach LIKE '%" + textBox1.Text + "%' and MaSach <> 'N/A'");
            if (rb4.Checked)
                HH = db.getDS("Select * from Sach Where TenTG LIKE '%" + textBox1.Text + "%' and MaSach <> 'N/A'");
            if (rb6.Checked)
                HH = db.getDS("Select * from Sach Where MaTL LIKE '%" + textBox1.Text + "%' and MaSach <> 'N/A'");
            if (rb7.Checked)
                HH = db.getDS("Select * from Sach Where NhaCungCap LIKE '%" + textBox1.Text + "%'and MaSach <> 'N/A'");
            if (rb1.Checked)
                HH = db.getDS("Select * from Sach Where (MaSach <> 'N/A') and (MaSach LIKE '%" + textBox1.Text + "%' or TenSach LIKE '%" + textBox1.Text + "%' or TenTG LIKE '%" + textBox1.Text + "%' or NhaCungCap LIKE '%" + textBox1.Text + "%' or MaTL LIKE '%" + textBox1.Text + "%')");
            dataGridView1.DataSource = HH;
        }
    }
}
